<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "website".
 *
 * @property string $id
 * @property string $url
 * @property string $title
 * @property string $desc
 * @property string $page_view
 * @property string $category_id
 * @property integer $update_at
 * @property integer $create_at
 *
 * @property Browse[] $browses
 * @property Category $category
 */
class Website extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'website';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['url', 'create_at'], 'required'],
            [['page_view', 'category_id', 'update_at', 'create_at'], 'integer'],
            [['url', 'favicon_url', 'desc'], 'string', 'max' => 1024],
            [['title'], 'string', 'max' => 100],
            [['category_id'], 'exist', 'skipOnError' => true, 'targetClass' => Category::className(), 'targetAttribute' => ['category_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'url' => Yii::t('app', 'Url'),
            'favicon_url' => Yii::t('app', 'ICO'),
            'title' => Yii::t('app', '名称'),
            'desc' => Yii::t('app', '描述'),
            'page_view' => Yii::t('app', '浏览次数'),
            'category_id' => Yii::t('app', '分类名称'),
            'update_at' => Yii::t('app', '更新时间'),
            'create_at' => Yii::t('app', '创建时间'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBrowses()
    {
        return $this->hasMany(Browse::className(), ['website_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCategory()
    {
        return $this->hasOne(Category::className(), ['id' => 'category_id']);
    }

    /**
     * @inheritdoc
     * @return WebsiteQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new WebsiteQuery(get_called_class());
    }
}
